﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.XPath ;
using System.Xml;

namespace MapSurface.UIModelElement
{
    public class UpdateUIModel:XPathNavigator
    {
        private string _xmiFile;
        private XmlDocument _docXMI;
        private XPathNavigator _navigator;
        private XmlNamespaceManager manager;

        public XmlNamespaceManager Manager
        {
            get { return manager; }
            set { manager = value; }
        }
       

        public UpdateUIModel(string fileName)
        {

            _xmiFile = fileName;
            _docXMI = new XmlDocument();
            _docXMI.Load(fileName);

            _navigator = _docXMI.CreateNavigator();
            manager = new XmlNamespaceManager(_docXMI.NameTable);
            manager.AddNamespace("UIModel", "http://www.omg.org/XMI");

         }
        public String deleteUINode( string name)
        {
            XPathNavigator nav=_navigator.SelectSingleNode("//containsUIElement[@name='" + name + "']");
            if(nav!=null && _navigator.CanEdit)
            {
                string id=null;
                if (nav.IsNode)
                    id = nav.GetAttribute("id",nav.GetNamespace("id"));
                nav.DeleteSelf();
                save(null);
                return id;
            }
            return null;
        }
        public void save(String newName)
        {
            if (newName == null)
                newName = _xmiFile;
            _docXMI.Save(_xmiFile);
        }
        public override string BaseURI
        {
            get { throw new NotImplementedException(); }
        }

        public override XPathNavigator Clone()
        {
            throw new NotImplementedException();
        }

        public override bool IsEmptyElement
        {
            get { throw new NotImplementedException(); }
        }

        public override bool IsSamePosition(XPathNavigator other)
        {
            throw new NotImplementedException();
        }

        public override string LocalName
        {
            get { throw new NotImplementedException(); }
        }

        public override bool MoveTo(XPathNavigator other)
        {
            throw new NotImplementedException();
        }

        public override bool MoveToFirstAttribute()
        {
            throw new NotImplementedException();
        }

        public override bool MoveToFirstChild()
        {
            throw new NotImplementedException();
        }

        public override bool MoveToFirstNamespace(XPathNamespaceScope namespaceScope)
        {
            throw new NotImplementedException();
        }

        public override bool MoveToId(string id)
        {
            throw new NotImplementedException();
        }

        public override bool MoveToNext()
        {
            throw new NotImplementedException();
        }

        public override bool MoveToNextAttribute()
        {
            throw new NotImplementedException();
        }

        public override bool MoveToNextNamespace(XPathNamespaceScope namespaceScope)
        {
            throw new NotImplementedException();
        }

        public override bool MoveToParent()
        {
            throw new NotImplementedException();
        }

        public override bool MoveToPrevious()
        {
            throw new NotImplementedException();
        }

        public override string Name
        {
            get { throw new NotImplementedException(); }
        }

        public override System.Xml.XmlNameTable NameTable
        {
            get { throw new NotImplementedException(); }
        }

        public override string NamespaceURI
        {
            get { throw new NotImplementedException(); }
        }

        public override XPathNodeType NodeType
        {
            get { throw new NotImplementedException(); }
        }

        public override string Prefix
        {
            get { throw new NotImplementedException(); }
        }

        public override string Value
        {
            get { throw new NotImplementedException(); }
        }
    }
}
